package restless.core.audio {
	
	import flash.events.Event;
	import restless.core.audio.RLESoundItem;
	import flash.media.SoundTransform;
	
	/**
	 * 
	 * @author Jordan Laine
	 * 
	 */
	
	public class RLEMusicItem extends RLESoundItem {
		private var bInTrack:Boolean;
		private var track:RLEMusicTrack;
		private var lineID:String;
		private var locationInLine:int;
		private var music:RLEMusic;
		
		public function RLEMusicItem(music:RLEMusic) {
			super();
			this.music = music;
		}
		
		public function playInLine(location:int, lineID:String):void {
			locationInLine = location;
			this.lineID = lineID;
			play();
			channel.addEventListener(Event.SOUND_COMPLETE, soundComplete, false, 0, true);
		}
		
		public function setTrack(track:RLEMusicTrack, lineID:String):void {
			bInTrack = true;
			this.lineID = lineID;
			this.track = track;
		}
		
		override protected function soundComplete(e:Event):void {
			if (bInTrack) { 
				music.playNextClipInLine(lineID, locationInLine);
			}
			if (bRepeat) {
				play();
			}
			//super.soundComplete(e);
			//tell the music class that it should play the next sample
		}
		
		override public function stop():void {
			super.stop();
			locationInLine = -1;
			lineID = "";
		}
		
	}

}